

var vm = new Vue({
    el:"#app",
    data:{
        pageModel: '',
        messages:'',
        dept:'',
        count: 0
    },
    methods:{
        getStaffList:function () {
            let name = $("input[name='name']").val();
            let deptName = $(".deptName").val();
            if (deptName === "请选择"){
                deptName = "";
            }
            let staffStatus = $("input[name='staffStatus']").eq(0).attr("checked")?1:0;
            axios({
                method:'post',
                url:'/staff/queryStaffByCondition',
                params:{"name":name,"deptName":deptName,"staffStatus":staffStatus,"pageNum":1}
            }).then(function(result){
                vm.pageModel = result.data;
                vm.messages=result.data.data;
            }).catch(function (err) {
                console.log(err);
            })
        },
        getDeptList:function () {
            axios.post("/dept/queryDept").then(
                function(result){
                    vm.dept=result.data;
                    console.log(vm.dept);
                },function (err) {
                    console.log(err);
                }
            )
        },
        changePageNum:function (num) {
            let name = $("input[name='name']").val();
            let deptName = $(".deptName").val();
            if (deptName === "请选择"){
                deptName = "";
            }
            let staffStatus = $("input[name='staffStatus']").eq(0).attr("checked")?1:0;
            axios({
                method:'post',
                url:'/staff/queryStaffByCondition',
                params:{"name":name,"deptName":deptName,"staffStatus":staffStatus,"pageNum":num}
            }).then(function(result){
                vm.pageModel = result.data;
                vm.messages=result.data.data;
            }).catch(function (err) {
                console.log(err);
            })
        }
    },
    //页面加载完自动执行
    mounted(){
        this.getStaffList();
        this.getDeptList();
    }
})

function toStaffInfo(t){
    let staffId = $(t).parent().siblings().eq(0).html();
    location.href = "../../../../templates/sysManage/staffManage/staffInfo.html?staffId=" + staffId;
}

function toUpdate(t){
    let staffId = $(t).parent().siblings().eq(0).html();

    location.href = "../../../../templates/sysManage/staffManage/staffUpdate.html?staffId=" + staffId;
}

function deleteStaff(t){
    let staffId = $(t).parent().siblings().eq(0).html();

    let flag = confirm('确认删除该员工么？');
    if (flag){
        $.ajax({
            url:"/staff/deleteStaff",
            type:"post",
            data:{"staffId":staffId},
            dataType:"json",
            success:function (result){
                if (result === true){
                    alert("删除成功");
                    location.href = "../../../../templates/sysManage/staffManage/staffList.html";
                }else {
                    alert("删除失败");
                }
            }
        })
    }
}

function toStaffAdd(){
    location.href = "../../../../templates/sysManage/staffManage/staffAdd.html";
}



